package com.jiang.专题.排序.Q75;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/03/17 20:39
 */
class Solution {
    public void sortColors(int[] nums) {
        int n = nums.length;
        int pre = 0, after = n - 1;
        for (int i = 0; i <= after; i++) {
            while (nums[i] == 2 && i < after) {
                nums[i] = nums[after];
                nums[after] = 2;
                after--;
            }
            if (nums[i] == 0) {
                nums[i] = nums[pre];
                nums[pre] = 0;
                pre++;
            }
        }
    }
}
